package tp.pr5.console;

import java.util.Scanner;

import tp.pr5.Game;
import tp.pr5.GameController;
import tp.pr5.Parser;
import tp.pr5.commands.Command;
import tp.pr5.commands.exceptions.CommandExecutionException;
import tp.pr5.commands.exceptions.WrongCommandFormatException;

public class GameControllerConsole extends GameController{

	public GameControllerConsole(Game g) {
		super(g);
	}
	public void runGame()
	{
		this.game.requestStart();
		Command c=null;
		Scanner scan=new Scanner(System.in);
		String token;
		do
		{
		try//Este try-cathc es la captura de la exception de formato de cadena.
		{	
			System.out.print("> ");
			token=scan.nextLine();
			c=Parser.parseCommand(token);
			this.game.executeCommand(c);
			
		}
		catch(WrongCommandFormatException e)
		{
			this.game.requestError("What?");
			
		}
		}
		while (!this.game.isOver());
		this.game.requestQuit();
	}

}
